<template>
  <div>
  <el-form  :model='searchInfo' inline>
    <el-form-item>
      <el-input clearable v-model="searchInfo.typeName" placeholder="请输入电影类型" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList">查询</el-button>
      <el-button icon="el-icon-refresh-right" @click="resetForm">重置</el-button>
    </el-form-item>
    <el-form-item>
      <el-button type="success" @click="openWin()">添加</el-button>
    </el-form-item>
  </el-form>
  <el-table :data=TypeList  border >
    <el-table-column label="编号" prop="typeId"  align="center" width="50px "  />
    <el-table-column label="类型名称" prop="typeName"  align="center" />
    <el-table-column label="类型介绍" prop="profile" align="center" show-overflow-tooltip width="500px" ></el-table-column>
    <el-table-column label="操作"  align="center" >
      <template slot-scope="scope">
        <el-button type="success" size="small" @click="openWin(scope.row)">修改</el-button>
        <el-button type="danger" size="small" @click="delInfo(scope.row.typeId)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
    <el-pagination layout="total,prev,pager,next,sizes,jumper"
                   :total="pageInfo.totalCount"
                   :page-size="pageInfo.pageSize"
                   :current-page="pageInfo.currPage"
                   :page-sizes="[5,10,20,30,50,100]"
                   @size-change="sizeChange"
                   @current-change="currentChange"
    />
  </div>
</template>

<script>

export default {
  name: 'FileType',
  data () {
    return {
      TypeList: [],
      searchInfo: {
        typeName: '',
        page: 1,
        limit: 5
      },
      pageInfo: {}
    }
  },
  methods: {
    getList () {
      this.$http.get('/sys/type/movie/list', this.searchInfo).then(({ data }) => {
        if (data.code === 200) {
          console.log(data.data.list)
          this.TypeList = data.data.list
          this.pageInfo = data.data
        } else {
          this.$confirm(data.msg)
        }
      })
    },
    resetForm () {
      this.searchInfo.typeName = ''
      this.getList()
    },
    openWin (id) {
      if (id) {
        this.$router.push('TypeEdit?typeId=' + id.typeId)
      } else {
        this.$router.push('TypeEdit')
      }
    },
    delInfo (id) {
      this.$confirm('确定删除该电影吗', '询问').then(() => {
        this.$axios.delete(`/sys/type/movie/delete/${id}`).then(({ data }) => {
          if (data.code === 200) {
            this.$message({
              message: '删除成功',
              type: 'success',
              onClose: () => {
                this.getList()
              }
            })
          } else {
            this.$alert('删除失败!', { type: 'error' })
          }
        })
      })
    },
    sizeChange (limit) {
      this.searchInfo.limit = limit
      this.getList()
    },
    currentChange (page) {
      this.searchInfo.page = page
      this.getList()
    }
  },
  created () {
    this.$nextTick(() => {
      this.getList()
    })
  }
}
</script>

<style scoped>

</style>
